<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<script type="text/javascript">
	var customergrid;
	$(function() {

		customergrid = $('#customergrid')
				.datagrid(
						{
							//title : '商品列表',
							url : '${ctx}/autoinn/customer/list',
							striped : true,
							rownumbers : true,
							pagination : true,
							singleSelect : true,
							idField : 'customerId',
							sortName : 'subscribe_time',
							sortOrder : 'desc',
							pageSize : 50,
							pageList : [ 10, 20, 30, 40, 50, 100, 200, 300,
									400, 500 ],
							frozenColumns : [ [ {
								width : '120',
								title : '用户昵称',
								field : 'nickname',
								
							} ,
							{
								width : '50',
								title : '性别',
								field : 'sex',
								formatter : function(value, row) {
									if (value==0) {
										return sy.formatString("<span align='center'>女</span>");
									} else {
										return sy.formatString("<span align='center'>男</span>");
									}
								}
							},
							{
								width : '60',
								title : '所在城市',
								field : 'city'
							},{
								width : '60',
								title : '所在省份',
								field :'province'
							},{
								width : '60',
								title :'所在国家',
								field : 'country'
							},{
								width : '120',
								title : '用户申请时间',
								field : 'applicationTime',
								sortable : true
							},{
								width : '60',
								title : '状态',
								field : 'status',
								formatter : function(value, row) {
									if (value==0) {
										return sy.formatString("<span align='center'>未开通</span>");
									} else {
										return sy.formatString("<span align='center'>已开通</span>");
									}
								}
							},{
								width : '60',
								title : '用户积分',
								field : 'integral'
							},{
								width : '100',
								title : '联系电话',
								field : 'phoneNum'
							},{
								width : '120',
								title : '会员卡号',
								field : 'vipNum'
							},{
								width :'60',
								title : '余额',
								field : 'surplus'
							}] ],
							columns : [ [
									
									{
										width : '180',
										title : '操作',
										field : 'action',
										formatter : function(value, row) {
											var str = "";
											str += sy
											.formatString(
													'<span onclick="customerremoveFun(\'{0}\');" style="margin-left:3px;cursor:pointer;">【{1}】</span>',
													row.customerId, "删除");
											<shiro:hasPermission name="/autoinn/customer/addcoupon/pro">
											str += sy
											.formatString(
													'<span onclick="customerupdateFun(\'{0}\',\'{1}\',\'{2}\');" style="margin-left:3px;cursor:pointer;">【{3}】</span>',
													row.customerId,row.openid,row.wxAccount, "发放优惠");
											</shiro:hasPermission>
											<shiro:hasPermission name="/autoinn/recharge/add">
											str +=sy
											.formatString(
													'<span onclick="rechargeraddFun(\'{0}\');" style="margin-left:3px;cursor:pointer;">【{1}】</span>',
													row.customerId, "充值");
										    </shiro:hasPermission>
											return str;
										}
									} ] ],
							toolbar : '#customertoolbar',
							onBeforeLoad : function(param) {
								parent.$.messager.progress({
									text : '数据加载中....'
								});
							},
							onLoadSuccess : function(data) {
								$('.iconImg').attr('src', sy.pixel_0);
							
								parent.$.messager.progress('close');
							}
							
							
						});
	});
	
	
	
	//c充值
	var rechargeraddFun = function(customerid) {
		$('<div/>').dialog({
			href : '${ctx}/autoinn/recharge/inser?customerid='+customerid,
			width : 640,
			height : 230,
			modal : true,
			title : '添加充值',
			buttons : [ {
				text : '添加',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#recharaddform').form('submit', {
						url : '${ctx}/autoinn/recharge/add',
						success : function(result) {

							try {
								var r = $.parseJSON(result);
								if (r.success) {
									//rechargegrid.datagrid('reload');// 刷新数据  
									d.dialog('destroy');
									$.messager.show({
										title : '温馨提示',
										msg : r.message
									});
								}
							

							} catch (e) {
								$.messager.alert('温馨提示', e.message);
								return;
							}

						}

					});
				}

			} ],
			onLoad : function() {
				//$("#res_updateForm").form('load',entity);

			},
			onClose : function() {
				$(this).dialog('destroy');
			}
		});

	};
	
	//修改
	var customerupdateFun = function(id,openId,wxaccount) {
		$('<div/>').dialog({
			href : '${ctx}/autoinn/customer/cofang?id=' + id+"&openid="+openId
					+"&wxaccount="+wxaccount,
			width : 640,
			height : 160,
			modal : true,
			title : '发放优惠券',
			buttons : [ {
				text : '发放',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');

					$('#customerjuanupdateForms').form('submit', {
						url : '${ctx}/autoinn/customer/addcoupon/pro',
						success : function(result) {
							try {
								var r = $.parseJSON(result);

								if (r.success) {
									customergrid.datagrid('reload'); // 刷新数据  
									d.dialog('destroy');
								}

								$.messager.show({
									title : '温馨提示',
									msg : r.message
								});

							} catch (e) {
								$.messager.alert('温馨提示', e.message);
								return;
							}

						}

					});

				}

			} ],
			onLoad : function() {
				//$("#res_updateForm").form('load',entity);

			},
			onClose : function() {
				$(this).dialog('destroy');
			}
		});

	};

	var customerexportXls=function(){
		window.location.href ="${ctx}/autoinn/customer/exportXls";
	}


	//移除
	var customerremoveFun = function(id) {
		parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
			if (r) {
				$.post('${ctx}/autoinn/customer/delete/' + id, {
					id : id
				}, function(data) {
					customergrid.datagrid('reload');
					$.messager.alert('温馨提示', data.message);
				}, 'json');
			}
		});
	};
	
	
</script>
<!-- 界面布局  -->
<div class="easyui-layout" style="width: 100%; height: 100%;"
	data-options="fit:true,border:false">

	<div id="customertoolbar" style="display: none;">

			<table>
			<tr>
				<td>
					<form id="customersearchForm">
						<table>
							<tr style="font-size: 13px;">
								<td>会员昵称</td>
								<td><input name="nickname" style="width: 80px;" /></td>
								<td>会员卡号</td>
								<td><input name="vipNum" style="width: 80px;" /></td>
								<td>会员等级</td>
								<td><select name="level" style="width: 120px;text-align:center;" >
								   <option value="">--请选择--</option>
								   <option value="0">普通会员</option>
								   <option value="1">青铜会员</option>
								   <option value="2">白银会员</option>
								   <option value="3">黄金会员</option>
								   <option value="4">白金会员</option>
								   <option value="5">钻石会员</option>
								</select></td>
								<td>电话号码</td>
								<td><input name="phoneNum" style="width:80px;"/></td>
								<td>申请时间</td>
								<td><input name="starinnertime" class="Wdate"
									onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
									readonly="readonly" style="width: 120px;" />-<input
									name="endinnertime" class="Wdate"
									onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
									readonly="readonly" style="width: 120px;" /></td>
								
								<td><a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-search',plain:true"
									onclick="customergrid.datagrid('load',sy.serializeObject($('#customersearchForm')));">过滤</a><a
									href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-reload',plain:true"
									onclick="$('#customersearchForm input').val('');customergrid.datagrid('load',{});">重置过滤</a>
									<a href="javascript:customerexportXls();" class="easyui-linkbutton"
								data-options="iconCls:'icon-redo',plain:true" onclick="">导出</a>
									</td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
			
		</table>
			
	</div>
	<div data-options="region:'center',title:'消费者管理'" style="padding: 2px;">
		<div class="easyui-layout" data-options="fit : true,border : false">
			<div data-options="region:'center',border:false">
				<table id="customergrid" data-options="fit:true,border:false"></table>
			</div>
		</div>
	</div>

</div>